/*
 * IwoNew.java
 * 
 * Copyright (c) 2012 Supin P Surendran <supinps@gmail.com>.
 * 
 * This file is part of InventoryMan.
 * 
 * InventoryMan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * InventoryMan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with InventoryMan.  If not, see <http ://www.gnu.org/licenses/>.
 */

/*
 * IwoNew.java
 *
 * Created on 20 Dec, 2012, 11:17:16 AM
 */

package InventoryMan;

import java.sql.SQLException;

/**
 *
 * @author Supin P Surendran <supinps@gmail.com>
 */
public class LcrNew extends javax.swing.JInternalFrame {

    /** Creates new form IwoNew
     * @param conn Connection to the Database
     */
    @SuppressWarnings("static-access")
    public LcrNew(java.sql.Connection conn) {
        imConnection=conn;
        save=false;
        itemCodes=new java.util.HashMap<Integer, Integer>();
        iwoQty=new java.util.HashMap<Integer, Integer>();
        iwoArea=new java.util.HashMap<Integer, Integer>();
        IwoNo=new javax.swing.DefaultComboBoxModel();
        tableIwo=new javax.swing.table.DefaultTableModel(new Object[]{"Sl No","Product","Quantity","Area","Remarks"},0);
        tableLcr=new javax.swing.table.DefaultTableModel(new Object[]{"Sl No","Product","No. of PCS/Rolls","No. of Bundles","Remarks"},0);
        initComponents();
        TblIwo.setModel(tableIwo);
        TblLcr.setModel(tableLcr);
        ac.decorate(CmbIwo);
        initIwoCombo();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TxtLcrNo = new javax.swing.JTextField();
        LcrDate = new org.jdesktop.swingx.JXDatePicker();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        CmbIwo = new org.jdesktop.swingx.JXComboBox();
        jLabel2 = new javax.swing.JLabel();
        TxtLrNo = new javax.swing.JTextField();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TblIwo = new javax.swing.JTable();
        BnAdd = new javax.swing.JButton();
        BnFetch = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        TblLcr = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        BnRemove = new javax.swing.JButton();
        BnSave = new javax.swing.JButton();
        BnCancel = new javax.swing.JButton();

        setTitle("New LCR");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon_small.png"))); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("IWO No :");

        LcrDate.setDate(new java.util.Date());

        jLabel3.setText("LCR No :");

        jLabel4.setText("LCR Date :");

        CmbIwo.setModel(IwoNo);

        jLabel2.setText("LR/RR No :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TxtLrNo, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(CmbIwo, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(LcrDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(TxtLcrNo, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                .addGap(622, 622, 622))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(CmbIwo, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(53, 53, 53))
                    .addComponent(TxtLcrNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(TxtLrNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(LcrDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34))
        );

        jSplitPane1.setDividerLocation(600);

        jLabel5.setText("IWO Items");

        TblIwo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(TblIwo);

        BnAdd.setText("Add >>");
        BnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnAddActionPerformed(evt);
            }
        });

        BnFetch.setText("Fetch Items");
        BnFetch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnFetchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
                    .addComponent(jLabel5)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(BnFetch, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(BnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BnAdd)
                    .addComponent(BnFetch)))
        );

        jSplitPane1.setLeftComponent(jPanel2);

        TblLcr.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(TblLcr);

        jLabel6.setText("LCR Items");

        BnRemove.setText("<< Remove");
        BnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnRemoveActionPerformed(evt);
            }
        });

        BnSave.setText("Gen. LCR No.");
        BnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnSaveActionPerformed(evt);
            }
        });

        BnCancel.setText("Cancel");
        BnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addContainerGap(504, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(BnRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(BnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 234, Short.MAX_VALUE)
                        .addComponent(BnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BnRemove)
                    .addComponent(BnSave)
                    .addComponent(BnCancel)))
        );

        jSplitPane1.setRightComponent(jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1186, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 391, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BnFetchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnFetchActionPerformed
        try {
            tableLcr.getDataVector().removeAllElements();
            TblLcr.repaint();
            tableIwo.getDataVector().removeAllElements();
            TblLcr.repaint();
            stmtItems=imConnection.createStatement();
            replyItems=stmtItems.executeQuery("SELECT iwo_item.sl_no,item.code,item.name,iwo_item.quantity,item.width,item.length,indent_item.remarks " +
                                              "FROM iwo_item INNER JOIN iwo_entry INNER JOIN indent_item INNER JOIN item INNER JOIN indent_entry " +
                                              "WHERE iwo_item.lcr=0 AND iwo_entry.indent_id=indent_item.indent_id AND iwo_item.item_code=indent_item.item_code AND iwo_entry.id=iwo_item.iwo_id AND iwo_item.item_code=item.code AND iwo_entry.indent_id=indent_entry.id and iwo_item.iwo_id="+IwoNo.getSelectedItem().toString());
            while(replyItems.next()) {
                int sl=replyItems.getInt("sl_no");
                itemCodes.put(sl,replyItems.getInt("code"));
                String name=replyItems.getString("name");
                int qty=replyItems.getInt("quantity");
                int area=replyItems.getInt("length")*replyItems.getInt("width");
                String rmrks=replyItems.getString("remarks");
                tableIwo.addRow(new Object[]{sl,name,qty,area,rmrks});
            }
        }catch(java.sql.SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_BnFetchActionPerformed

    private void BnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnAddActionPerformed
        BnFetch.setEnabled(false);
        rowIndex=TblIwo.getSelectedRow();
        int sl=Integer.parseInt(tableIwo.getValueAt(rowIndex, 0).toString());
        String name=tableIwo.getValueAt(rowIndex, 1).toString();
        iwoQty.put(sl, Integer.parseInt(tableIwo.getValueAt(rowIndex, 2).toString()));
        iwoArea.put(sl, Integer.parseInt(tableIwo.getValueAt(rowIndex, 3).toString()));
        String rmrks=tableIwo.getValueAt(rowIndex, 4).toString();
        tableLcr.addRow(new Object[]{sl,name,1,1,rmrks});
        tableIwo.removeRow(rowIndex);
        try {
            stmtUpdate = imConnection.prepareStatement("UPDATE iwo_item SET lcr=? WHERE iwo_id=? and sl_no=?");

            stmtStock=imConnection.createStatement();
            replyStock=stmtStock.executeQuery("SELECT stock FROM item WHERE code="+itemCodes.get(sl));
            replyStock.next(); {
                oldStock=replyStock.getInt("stock");
            }
            stmtStockUpdate=imConnection.prepareStatement("UPDATE item SET stock=? WHERE code=?");
            newStock=oldStock-iwoQty.get(sl);
            stmtStockUpdate.setInt(1, newStock);
            stmtStockUpdate.setInt(2, itemCodes.get(sl));
            stmtStockUpdate.executeUpdate();
            
            stmtUpdate.setBoolean(1, true);
            stmtUpdate.setInt(2, Integer.parseInt(CmbIwo.getSelectedItem().toString()));
            stmtUpdate.setInt(3, sl);
            stmtUpdate.executeUpdate();
        } catch (SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_BnAddActionPerformed

    private void BnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnRemoveActionPerformed
        rowIndex=TblLcr.getSelectedRow();
        int sl=Integer.parseInt(tableLcr.getValueAt(rowIndex, 0).toString());
        String name=tableLcr.getValueAt(rowIndex, 1).toString();
        int qty=iwoQty.get(sl);
        int area=iwoArea.get(sl);
        String rmrks=tableLcr.getValueAt(rowIndex, 4).toString();
        tableIwo.addRow(new Object[]{sl,name,qty,area,rmrks});
        tableLcr.removeRow(rowIndex);
         try {
             stmtStock=imConnection.createStatement();
            replyStock=stmtStock.executeQuery("SELECT stock FROM item WHERE code="+itemCodes.get(sl));
            replyStock.next(); {
                oldStock=replyStock.getInt("stock");
            }
            stmtStockUpdate=imConnection.prepareStatement("UPDATE item SET stock=? WHERE code=?");
            newStock=oldStock+iwoQty.get(sl);
            stmtStockUpdate.setInt(1, newStock);
            stmtStockUpdate.setInt(2, itemCodes.get(sl));
            stmtStockUpdate.executeUpdate();

            stmtUpdate = imConnection.prepareStatement("UPDATE iwo_item SET lcr=? WHERE iwo_id=? and sl_no=?");
            stmtUpdate.setBoolean(1, false);
            stmtUpdate.setInt(2, Integer.parseInt(CmbIwo.getSelectedItem().toString()));
            stmtUpdate.setInt(3, sl);
            stmtUpdate.executeUpdate();
        } catch (SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_BnRemoveActionPerformed

    private void BnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnSaveActionPerformed
        if(tableLcr.getRowCount()>0) {
            try {
                if(!save) {
                    stmtIwo.execute("LOCK TABLES lcr_entry WRITE");
                    replyIwo=stmtIwo.executeQuery("SELECT MAX(id) FROM lcr_entry");
                    replyIwo.next();
                    newId=replyIwo.getInt("MAX(id)")+1;
                    TxtLcrNo.setText(Integer.toString(newId));
                    save=!save;
                    BnSave.setText("Save");
                }
                else {
                    //Entry
                    stmtLcr=imConnection.prepareStatement("INSERT INTO lcr_entry VALUES (?,?,?,?)");
                    stmtLcr.setInt(1, Integer.parseInt(TxtLcrNo.getText()));
                    stmtLcr.setInt(2, Integer.parseInt(CmbIwo.getSelectedItem().toString()));
                    stmtLcr.setDate(3, new java.sql.Date(LcrDate.getDate().getTime()));
                    stmtLcr.setString(4, TxtLrNo.getText());
                    stmtLcr.executeUpdate();
                    stmtIwo.execute("UNLOCK TABLES");
                    //Items
                    for(int i=0;i<tableLcr.getRowCount();i++) {
                        stmtLcr=imConnection.prepareStatement("INSERT INTO lcr_item VALUES(?,?,?,?,?,?)");
                        stmtLcr.setInt(1, Integer.parseInt(TxtLcrNo.getText()));//LCR no
                        stmtLcr.setInt(2, i+1);//SL no
                        stmtLcr.setInt(3, itemCodes.get(Integer.parseInt(tableLcr.getValueAt(i, 0).toString())));//Item Code
                        stmtLcr.setInt(4, Integer.parseInt(tableLcr.getValueAt(i, 2).toString()));// No of PCS
                        stmtLcr.setInt(5, Integer.parseInt(tableLcr.getValueAt(i, 3).toString()));// No of Bundle
                        stmtLcr.setString(6, tableLcr.getValueAt(i, 4).toString());//Remarks if any
                        stmtLcr.executeUpdate();
                    }
                    this.dispose();
                }
            }catch(java.sql.SQLException ex) {
                javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
                this.dispose();
            }catch(java.lang.NumberFormatException ex) {
                javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
                this.dispose();
            }
        }
        else {
            javax.swing.JOptionPane.showMessageDialog(this, "No items selected");
        }
    }//GEN-LAST:event_BnSaveActionPerformed

    private void BnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_BnCancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BnAdd;
    private javax.swing.JButton BnCancel;
    private javax.swing.JButton BnFetch;
    private javax.swing.JButton BnRemove;
    private javax.swing.JButton BnSave;
    private org.jdesktop.swingx.JXComboBox CmbIwo;
    private org.jdesktop.swingx.JXDatePicker LcrDate;
    private javax.swing.JTable TblIwo;
    private javax.swing.JTable TblLcr;
    private javax.swing.JTextField TxtLcrNo;
    private javax.swing.JTextField TxtLrNo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    // End of variables declaration//GEN-END:variables

    /**
     * 
     */
    //Manually Declared Variables
    java.sql.Connection imConnection;
    java.sql.Statement stmtIwo;
    java.sql.PreparedStatement stmtUpdate;
    java.sql.PreparedStatement stmtLcr,stmtStockUpdate;
    java.sql.Statement stmtItems,stmtStock;
    java.sql.ResultSet replyItems,replyStock;
    java.sql.ResultSet replyIwo;
    java.sql.ResultSet replyLcr;
    //DataStructures
    javax.swing.DefaultComboBoxModel IwoNo;
    javax.swing.table.DefaultTableModel tableIwo;
    javax.swing.table.DefaultTableModel tableLcr;
    javax.swing.JTextField TxtLcrQty;
    int rowIndex,newId;
    int oldStock,newStock;
    java.util.Map<Integer, Integer> itemCodes;
    java.util.Map<Integer, Integer> iwoQty;
    java.util.Map<Integer, Integer> iwoArea;
    boolean save;
    org.jdesktop.swingx.autocomplete.AutoCompleteDecorator ac;
    //End of Declarations
    /**
     * Fetches indent table and populates
     * indent no combobox
     */
    private void initIwoCombo() {
        try {
            stmtIwo = imConnection.createStatement();
            replyIwo = stmtIwo.executeQuery("SELECT id FROM iwo_entry");
            while(replyIwo.next()) {
                IwoNo.addElement(replyIwo.getInt("id"));
            }
        } catch (SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }    
}
